//
//  LSYTopMenuView.m
//  LSYReader
//
//  Created by Labanotation on 16/6/1.
//  Copyright © 2016年 okwei. All rights reserved.
//

#import "LSYTopMenuView.h"
#import "LSYMenuView.h"
@interface LSYTopMenuView ()
@property (nonatomic,strong) UIButton *back;
@property (nonatomic,strong) UIButton *more;
@property (nonatomic,strong) UIButton *source;
@property (nonatomic,strong) UILabel *titleLabel;
@end
@implementation LSYTopMenuView
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setup];
    }
    return self;
}
-(void)setup
{
    [self setBackgroundColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:0.8]];
    [self addSubview:self.titleLabel];
    [self addSubview:self.back];
    [self addSubview:self.source];
    [self addSubview:self.more];
}
-(void)setState:(BOOL)state
{
    _state = state;
    if (state) {
        [_more setImage:[[UIImage imageNamed:@"sale_discount_yellow"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]forState:UIControlStateNormal];
        return;
    }
    [_more setImage:[[UIImage imageNamed:@"sale_discount_yellow"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]forState:UIControlStateNormal];
}
-(UIButton *)back
{
    if (!_back) {
        _back = [LSYReadUtilites commonButtonSEL:@selector(backView) target:self];
        [_back setImage:[UIImage imageNamed:@"bg_back_white"] forState:UIControlStateNormal];
    }
    return _back;
}
-(UIButton *)more
{
    if (!_more) {
        _more = [UIButton buttonWithType:UIButtonTypeCustom];
        [_more addTarget:self action:@selector(moreOption) forControlEvents:UIControlEventTouchUpInside];
        [_more setTintColor:[UIColor whiteColor]];
        [_more setImage:[[UIImage imageNamed:@"sale_discount_yellow"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]forState:UIControlStateNormal];
    }
    return _more;
}

-(UIButton *)source
{
    if (!_source) {
        _source = [UIButton buttonWithType:UIButtonTypeCustom];
        [_source setTintColor:[UIColor whiteColor]];
        [_source addTarget:self action:@selector(sourceOption) forControlEvents:UIControlEventTouchUpInside];
        [_source setImage:[[UIImage imageNamed:@"ic_route_switch"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] forState:UIControlStateNormal];
    }
    return _source;
}

-(UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.font =[UIFont systemFontOfSize:20.f];
        _titleLabel.textAlignment = NSTextAlignmentCenter;
        _titleLabel.textColor = [UIColor whiteColor];
    }
    return _titleLabel;
}
-(void)moreOption
{
    if ([self.delegate respondsToSelector:@selector(menuViewMark:)]) {
        [self.delegate menuViewMark:self];
    }
}
-(void)sourceOption {
    if ([self.delegate respondsToSelector:@selector(menuViewSource:)]) {
        [self.delegate menuViewSource:self];
    }
}
-(void)backView
{
    if ([self.delegate respondsToSelector:@selector(menuViewBack:)]) {
        [self.delegate menuViewBack:self];
    }
}
-(void)layoutSubviews
{
    [super layoutSubviews];
    _back.frame = CGRectMake(0, [UIApplication sharedApplication].statusBarFrame.size.height, 40, 40);
    _source.frame = CGRectMake(ViewSize(self).width-50, [UIApplication sharedApplication].statusBarFrame.size.height, 40, 40);
    _more.frame = CGRectMake(ViewSize(self).width-90, [UIApplication sharedApplication].statusBarFrame.size.height, 40, 40);
    _titleLabel.frame = CGRectMake(50, [UIApplication sharedApplication].statusBarFrame.size.height, ViewSize(self).width-130, 40);
}

- (void)setTitle:(NSString *)title {
    _titleLabel.text = title;
}

@end
